package main

import (
	"fmt"
	"log"
	"net/http"
	"runtime"
)

func RootPage(w http.ResponseWriter, r *http.Request) {
	fmt.Printf("path: %s\n\n", r.URL.Path)
	header := r.Header

	for k, v := range header {
		// request header to response header
		w.Header().Add(k, v[0])
		//fmt.Println(k, v)
	}

	// add go version
	w.Header().Add("goVersion", runtime.Version())
	w.Header().Add("StatusCode", "200")

	fmt.Println("RemoteAddr", r.RemoteAddr)
	//fmt.Println("StatusCode", w.Header().Get("StatusCode"))

	fmt.Fprintf(w, r.RemoteAddr)
}

func main() {

	fmt.Println("Start Http Server ...")
	http.HandleFunc("/", RootPage)
	http.HandleFunc("/healthz", healthz)

	fmt.Println("http://0.0.0.0:8000")

	err := http.ListenAndServe(":8000", nil)

	if err != nil {
		log.Fatal(err)
	}

}

func healthz(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "healthz")
}
